<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>价格维护</title>
  </head>
  <body>
    <script type="text/javascript">
      var editPriceWin;
      var priceDS;
      Ext.onReady(function(){
        var priceId;
        Ext.QuickTips.init();
        Ext.BLANK_IMAGE_URL = '/javascripts/ext/resources/images/default/s.gif';
        //------------------------------业主Grid--------------------------------
        priceDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/price/getAllPrices'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'sub_type'
            },{
              name: 'price'
            }, {
              name: 'created_at'
            }, {
              name: 'updated_at'
            }])
        });
        //house的CM
        var priceCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),{
            id: 'common',
            header: '数据库编号',
            dataIndex: 'id',
            width: 30,
            hidden:true
          },{
            header: '类型',
            dataIndex: 'sub_type',
            width: 100
          },{
            header: '价格',
            dataIndex: 'price',
            width: 70
          },{
            header: '生成日期',
            dataIndex: 'created_at',
            renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
            width: 110
          },{
            header: '修改日期',
            dataIndex: 'updated_at',
            renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
            width: 110
          }
        ]);

        var priceGrid = new Ext.grid.GridPanel({
          store: priceDS,
          cm: priceCM,
          renderTo: 'price_search',
          loadMask: true,
          //width: 830,
          height: 200,
          //frame: true,
          collapsible: true,
          autoExpandColumn: 'common',
          title: '价格列表',
          frame: false
        });

        priceGrid.on('rowcontextmenu', function(housegrid, rowIndex, e){
          priceId = priceDS.getAt(rowIndex).get('id');
          e.preventDefault();
          rightClick.showAt(e.getXY());
        });
        var editPriceMenuItem = new Ext.menu.Item({
          text: '【编辑价格】',
          iconCls: 'editItem',
          handler: rightMenuEditPriceFn
        });

        function rightMenuEditPriceFn(grid, rowIndex, e){
          editPriceWin = new Ext.Window({
            layout: 'fit',
            width: 210,
            height: 130,
            closeAction: 'destroy',
            plain: true,
            modal: true,
            constrain:true,
            title: '编辑价格',
            autoLoad: {
              url: "/price/editPrice?price_id="+priceId,
              scripts: true
            }
          });
          editPriceWin.resizable = false;
          editPriceWin.show();
        }

        
        var rightClick = new Ext.menu.Menu({
          items: [editPriceMenuItem]
        });
        
        priceDS.load();
      })
    </script>
    <div id="price_search"></div>
  </body>
</html>
